package com.studentmanager.controller;

import com.studentmanager.service.TeachingCallingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Date;

@Controller
@RequestMapping("/calling")
public class TeachingCallingController {

    @Autowired
    private TeachingCallingService teachingCallingService;

    @RequestMapping("/calling_list")
    public String teacherList(){
        return "/calling/calling";
    }

    // 发布点名页面
    @GetMapping("/createCalling")
    public String createCallingPage(Model model) {
        // 这里加载需要的班级、教师信息等
        return "calling/teachercalling"; // 返回 Thymeleaf 页面
    }

    // 发布点名
    @PostMapping("/createCalling")
    public String createCalling(int classId, int teacherId,@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm") Date startTime,
                                @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm") Date endTime) {
        teachingCallingService.createTeachingCalling(classId, teacherId, startTime, endTime);
        return "redirect:/createdCalling";
    }

    // 学生签到页面
    @GetMapping("/signIn")
    public String studentSignInPage(Model model) {
        // 查询当前学生相关的点名记录
        return "calling/studentcalling"; // 返回学生签到页面
    }

    // 学生签到
    @PostMapping("/studentSignIn")
    public String studentSignIn(int stuInClassId, int callId, Date answerTime, String answerResult, String noAnswerReason) {
        teachingCallingService.studentSignIn(stuInClassId, callId, answerTime, answerResult, noAnswerReason);
        return "redirect:/student/signedIn";  // 显示签到成功页面
    }
}